<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>IO::Compress::FAQ -- Frequently Asked Questions about IO::Compress - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/IO::Compress::FAQ">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Compress::FAQ.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/IO::Compress::FAQ">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/IO::Compress::FAQ">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/IO::Compress::FAQ">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/IO::Compress::FAQ">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/IO::Compress::FAQ">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/IO::Compress::FAQ">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/IO::Compress::FAQ">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/IO::Compress::FAQ">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/IO::Compress::FAQ">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/IO::Compress::FAQ">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/IO::Compress::FAQ">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/IO::Compress::FAQ">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/IO::Compress::FAQ">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/IO::Compress::FAQ">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/IO::Compress::FAQ">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/IO::Compress::FAQ">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/IO::Compress::FAQ">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/IO::Compress::FAQ">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/IO::Compress::FAQ">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/IO::Compress::FAQ">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/IO::Compress::FAQ">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/IO::Compress::FAQ">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/IO::Compress::FAQ">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/IO::Compress::FAQ">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/IO::Compress::FAQ">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/IO::Compress::FAQ">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/IO::Compress::FAQ">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/IO::Compress::FAQ">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/IO::Compress::FAQ">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/IO::Compress::FAQ">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/IO::Compress::FAQ">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/IO::Compress::FAQ">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/IO::Compress::FAQ">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/IO::Compress::FAQ">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/IO::Compress::FAQ">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/IO::Compress::FAQ">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/IO::Compress::FAQ">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/IO::Compress::FAQ">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/IO::Compress::FAQ">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/IO::Compress::FAQ">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/IO::Compress::FAQ">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/IO::Compress::FAQ">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/IO::Compress::FAQ">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/IO::Compress::FAQ">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/IO::Compress::FAQ">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/IO::Compress::FAQ">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/IO::Compress::FAQ">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/IO::Compress::FAQ">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/IO::Compress::FAQ">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/IO::Compress::FAQ">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/IO::Compress::FAQ">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/IO::Compress::FAQ">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/IO::Compress::FAQ">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/IO::Compress::FAQ">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/IO::Compress::FAQ">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/IO::Compress::FAQ">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/IO::Compress::FAQ">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/IO::Compress::FAQ">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/IO::Compress::FAQ">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/IO::Compress::FAQ">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/IO::Compress::FAQ">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/IO::Compress::FAQ">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/IO::Compress::FAQ">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/IO::Compress::FAQ">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/IO::Compress::FAQ">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/IO::Compress::FAQ">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/IO::Compress::FAQ">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/IO::Compress::FAQ">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/IO::Compress::FAQ">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/IO::Compress::FAQ">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/IO::Compress::FAQ">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/IO::Compress::FAQ">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/IO::Compress::FAQ">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/IO::Compress::FAQ">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/IO::Compress::FAQ">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/IO::Compress::FAQ">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/IO::Compress::FAQ">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/IO::Compress::FAQ">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/IO::Compress::FAQ">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/IO::Compress::FAQ">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Compress::FAQ.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/IO::Compress::FAQ">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/IO::Compress::FAQ">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/IO::Compress::FAQ">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/IO::Compress::FAQ">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/IO::Compress::FAQ">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/IO::Compress::FAQ">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/IO::Compress::FAQ">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/IO::Compress::FAQ">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/IO::Compress::FAQ">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/IO::Compress::FAQ">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/IO::Compress::FAQ">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/IO::Compress::FAQ">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/IO::Compress::FAQ">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/IO::Compress::FAQ">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/IO::Compress::FAQ">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/IO::Compress::FAQ">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/IO::Compress::FAQ">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/IO::Compress::FAQ">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/IO::Compress::FAQ">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/IO::Compress::FAQ">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/IO::Compress::FAQ">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/IO::Compress::FAQ">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/IO::Compress::FAQ">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/IO::Compress::FAQ">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/IO::Compress::FAQ">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/IO::Compress::FAQ">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/IO::Compress::FAQ">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/IO::Compress::FAQ">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/IO::Compress::FAQ">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/IO::Compress::FAQ">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/IO::Compress::FAQ">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/IO::Compress::FAQ">5.35.1</a>
          <a class="dropdown-item active" href="./IO::Compress::FAQ.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Compress::FAQ.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./IO::Compress::FAQ.html">IO::Compress::FAQ</a>
          <div id="more">
            (<a href="./IO::Compress::FAQ.txt">source</a>,
            <a href="https://metacpan.org/pod/IO::Compress::FAQ">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#GENERAL">GENERAL</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Compatibility-with-Unix-compress/uncompress.">Compatibility with Unix compress/uncompress.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Accessing-.tar.Z-files">Accessing .tar.Z files</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#How-do-I-recompress-using-a-different-compression?">How do I recompress using a different compression?</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#ZIP">ZIP</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#What-Compression-Types-do-IO::Compress::Zip-&amp;-IO::Uncompress::Unzip-support?">What Compression Types do IO::Compress::Zip &amp; IO::Uncompress::Unzip support?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Can-I-Read/Write-Zip-files-larger-the-4-Gig?">Can I Read/Write Zip files larger the 4 Gig?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Can-I-write-more-that-64K-entries-is-a-Zip-files?">Can I write more that 64K entries is a Zip files?</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Zip-Resources">Zip Resources</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#GZIP">GZIP</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Gzip-Resources">Gzip Resources</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Dealing-with-concatenated-gzip-files">Dealing with concatenated gzip files</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Reading-bgzip-files-with-IO::Uncompress::Gunzip">Reading bgzip files with IO::Uncompress::Gunzip</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#ZLIB">ZLIB</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Zlib-Resources">Zlib Resources</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Bzip2">Bzip2</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Bzip2-Resources">Bzip2 Resources</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Dealing-with-Concatenated-bzip2-files">Dealing with Concatenated bzip2 files</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Interoperating-with-Pbzip2">Interoperating with Pbzip2</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#HTTP-&amp;-NETWORK">HTTP &amp; NETWORK</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Apache::GZip-Revisited">Apache::GZip Revisited</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Compressed-files-and-Net::FTP">Compressed files and Net::FTP</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#MISC">MISC</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#Using-InputLength-to-uncompress-data-embedded-in-a-larger-file/buffer.">Using InputLength to uncompress data embedded in a larger file/buffer.</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#SUPPORT">SUPPORT</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#MODIFICATION-HISTORY">MODIFICATION HISTORY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::FAQ.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./IO::Compress::FAQ.html#NAME">#</a>NAME</h1>

<p>IO::Compress::FAQ -- Frequently Asked Questions about IO::Compress</p>

<h1 id="DESCRIPTION"><a class="permalink" href="./IO::Compress::FAQ.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>Common questions answered.</p>

<h1 id="GENERAL"><a class="permalink" href="./IO::Compress::FAQ.html#GENERAL">#</a>GENERAL</h1>

<h2 id="Compatibility-with-Unix-compress/uncompress."><a class="permalink" href="./IO::Compress::FAQ.html#Compatibility-with-Unix-compress/uncompress.">#</a><a id="Compatibility"></a><a id="Compatibility-with-Unix-compress-uncompress"></a>Compatibility with Unix compress/uncompress.</h2>

<p>Although <code>Compress::Zlib</code> has a pair of functions called <code>compress</code> and <code>uncompress</code>, they are <i>not</i> related to the Unix programs of the same name. The <code>Compress::Zlib</code> module is not compatible with Unix <code>compress</code>.</p>

<p>If you have the <code>uncompress</code> program available, you can use this to read compressed files</p>

<pre><code>open F, &quot;uncompress -c $filename |&quot;;
while (&lt;F&gt;)
{
    ...</code></pre>

<p>Alternatively, if you have the <code>gunzip</code> program available, you can use this to read compressed files</p>

<pre><code>open F, &quot;gunzip -c $filename |&quot;;
while (&lt;F&gt;)
{
    ...</code></pre>

<p>and this to write compress files, if you have the <code>compress</code> program available</p>

<pre><code>open F, &quot;| compress -c $filename &quot;;
print F &quot;data&quot;;
...
close F ;</code></pre>

<h2 id="Accessing-.tar.Z-files"><a class="permalink" href="./IO::Compress::FAQ.html#Accessing-.tar.Z-files">#</a><a id="Accessing"></a>Accessing .tar.Z files</h2>

<p>The <code>Archive::Tar</code> module can optionally use <code>Compress::Zlib</code> (via the <code>IO::Zlib</code> module) to access tar files that have been compressed with <code>gzip</code>. Unfortunately tar files compressed with the Unix <code>compress</code> utility cannot be read by <code>Compress::Zlib</code> and so cannot be directly accessed by <code>Archive::Tar</code>.</p>

<p>If the <code>uncompress</code> or <code>gunzip</code> programs are available, you can use one of these workarounds to read <code>.tar.Z</code> files from <code>Archive::Tar</code></p>

<p>Firstly with <code>uncompress</code></p>

<pre><code>use strict;
use warnings;
use Archive::Tar;

open F, &quot;uncompress -c $filename |&quot;;
my $tar = Archive::Tar-&gt;new(*F);
...</code></pre>

<p>and this with <code>gunzip</code></p>

<pre><code>use strict;
use warnings;
use Archive::Tar;

open F, &quot;gunzip -c $filename |&quot;;
my $tar = Archive::Tar-&gt;new(*F);
...</code></pre>

<p>Similarly, if the <code>compress</code> program is available, you can use this to write a <code>.tar.Z</code> file</p>

<pre><code>use strict;
use warnings;
use Archive::Tar;
use IO::File;

my $fh = IO::File-&gt;new( &quot;| compress -c &gt;$filename&quot; );
my $tar = Archive::Tar-&gt;new();
...
$tar-&gt;write($fh);
$fh-&gt;close ;</code></pre>

<h2 id="How-do-I-recompress-using-a-different-compression?"><a class="permalink" href="./IO::Compress::FAQ.html#How-do-I-recompress-using-a-different-compression?">#</a><a id="How"></a><a id="How-do-I-recompress-using-a-different-compression"></a>How do I recompress using a different compression?</h2>

<p>This is easier that you might expect if you realise that all the <code>IO::Compress::*</code> objects are derived from <code>IO::File</code> and that all the <code>IO::Uncompress::*</code> modules can read from an <code>IO::File</code> filehandle.</p>

<p>So, for example, say you have a file compressed with gzip that you want to recompress with bzip2. Here is all that is needed to carry out the recompression.</p>

<pre><code>use IO::Uncompress::Gunzip &#39;:all&#39;;
use IO::Compress::Bzip2 &#39;:all&#39;;

my $gzipFile = &quot;somefile.gz&quot;;
my $bzipFile = &quot;somefile.bz2&quot;;

my $gunzip = IO::Uncompress::Gunzip-&gt;new( $gzipFile )
    or die &quot;Cannot gunzip $gzipFile: $GunzipError\n&quot; ;

bzip2 $gunzip =&gt; $bzipFile
    or die &quot;Cannot bzip2 to $bzipFile: $Bzip2Error\n&quot; ;</code></pre>

<p>Note, there is a limitation of this technique. Some compression file formats store extra information along with the compressed data payload. For example, gzip can optionally store the original filename and Zip stores a lot of information about the original file. If the original compressed file contains any of this extra information, it will not be transferred to the new compressed file using the technique above.</p>

<h1 id="ZIP"><a class="permalink" href="./IO::Compress::FAQ.html#ZIP">#</a>ZIP</h1>

<h2 id="What-Compression-Types-do-IO::Compress::Zip-&amp;-IO::Uncompress::Unzip-support?"><a class="permalink" href="./IO::Compress::FAQ.html#What-Compression-Types-do-IO::Compress::Zip-&amp;-IO::Uncompress::Unzip-support?">#</a><a id="What"></a><a id="What-Compression-Types-do-IO::Compress::Zip-IO::Uncompress::Unzip-support"></a>What Compression Types do IO::Compress::Zip &amp; IO::Uncompress::Unzip support?</h2>

<p>The following compression formats are supported by <code>IO::Compress::Zip</code> and <code>IO::Uncompress::Unzip</code></p>

<ul>

<li><p>Store (method 0)</p>

<p>No compression at all.</p>

</li>
<li><p>Deflate (method 8)</p>

<p>This is the default compression used when creating a zip file with <code>IO::Compress::Zip</code>.</p>

</li>
<li><p>Bzip2 (method 12)</p>

<p>Only supported if the <code>IO-Compress-Bzip2</code> module is installed.</p>

</li>
<li><p>Lzma (method 14)</p>

<p>Only supported if the <code>IO-Compress-Lzma</code> module is installed.</p>

</li>
</ul>

<h2 id="Can-I-Read/Write-Zip-files-larger-the-4-Gig?"><a class="permalink" href="./IO::Compress::FAQ.html#Can-I-Read/Write-Zip-files-larger-the-4-Gig?">#</a><a id="Can"></a><a id="Can-I-Read-Write-Zip-files-larger-the-4-Gig"></a>Can I Read/Write Zip files larger the 4 Gig?</h2>

<p>Yes, both the <code>IO-Compress-Zip</code> and <code>IO-Uncompress-Unzip</code> modules support the zip feature called <i>Zip64</i>. That allows them to read/write files/buffers larger than 4Gig.</p>

<p>If you are creating a Zip file using the one-shot interface, and any of the input files is greater than 4Gig, a zip64 complaint zip file will be created.</p>

<pre><code>zip &quot;really-large-file&quot; =&gt; &quot;my.zip&quot;;</code></pre>

<p>Similarly with the one-shot interface, if the input is a buffer larger than 4 Gig, a zip64 complaint zip file will be created.</p>

<pre><code>zip \$really_large_buffer =&gt; &quot;my.zip&quot;;</code></pre>

<p>The one-shot interface allows you to force the creation of a zip64 zip file by including the <code>Zip64</code> option.</p>

<pre><code>zip $filehandle =&gt; &quot;my.zip&quot;, Zip64 =&gt; 1;</code></pre>

<p>If you want to create a zip64 zip file with the OO interface you must specify the <code>Zip64</code> option.</p>

<pre><code>my $zip = IO::Compress::Zip-&gt;new( &quot;whatever&quot;, Zip64 =&gt; 1 );</code></pre>

<p>When uncompressing with <code>IO-Uncompress-Unzip</code>, it will automatically detect if the zip file is zip64.</p>

<p>If you intend to manipulate the Zip64 zip files created with <code>IO-Compress-Zip</code> using an external zip/unzip, make sure that it supports Zip64.</p>

<p>In particular, if you are using Info-Zip you need to have zip version 3.x or better to update a Zip64 archive and unzip version 6.x to read a zip64 archive.</p>

<h2 id="Can-I-write-more-that-64K-entries-is-a-Zip-files?"><a class="permalink" href="./IO::Compress::FAQ.html#Can-I-write-more-that-64K-entries-is-a-Zip-files?">#</a><a id="Can1"></a><a id="Can-I-write-more-that-64K-entries-is-a-Zip-files"></a>Can I write more that 64K entries is a Zip files?</h2>

<p>Yes. Zip64 allows this. See previous question.</p>

<h2 id="Zip-Resources"><a class="permalink" href="./IO::Compress::FAQ.html#Zip-Resources">#</a><a id="Zip"></a>Zip Resources</h2>

<p>The primary reference for zip files is the &quot;appnote&quot; document available at <a href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">http://www.pkware.com/documents/casestudies/APPNOTE.TXT</a></p>

<p>An alternatively is the Info-Zip appnote. This is available from <a href="ftp://ftp.info-zip.org/pub/infozip/doc/">ftp://ftp.info-zip.org/pub/infozip/doc/</a></p>

<h1 id="GZIP"><a class="permalink" href="./IO::Compress::FAQ.html#GZIP">#</a>GZIP</h1>

<h2 id="Gzip-Resources"><a class="permalink" href="./IO::Compress::FAQ.html#Gzip-Resources">#</a><a id="Gzip"></a>Gzip Resources</h2>

<p>The primary reference for gzip files is RFC 1952 <a href="http://www.faqs.org/rfcs/rfc1952.html">http://www.faqs.org/rfcs/rfc1952.html</a></p>

<p>The primary site for gzip is <a href="http://www.gzip.org">http://www.gzip.org</a>.</p>

<h2 id="Dealing-with-concatenated-gzip-files"><a class="permalink" href="./IO::Compress::FAQ.html#Dealing-with-concatenated-gzip-files">#</a><a id="Dealing"></a>Dealing with concatenated gzip files</h2>

<p>If the gunzip program encounters a file containing multiple gzip files concatenated together it will automatically uncompress them all. The example below illustrates this behaviour</p>

<pre><code class="plaintext">$ echo abc | gzip -c &gt;x.gz
$ echo def | gzip -c &gt;&gt;x.gz
$ gunzip -c x.gz
abc
def</code></pre>

<p>By default <code>IO::Uncompress::Gunzip</code> will <i>not</i> behave like the gunzip program. It will only uncompress the first gzip data stream in the file, as shown below</p>

<pre><code class="plaintext">$ perl -MIO::Uncompress::Gunzip=:all -e &#39;gunzip &quot;x.gz&quot; =&gt; \*STDOUT&#39;
abc</code></pre>

<p>To force <code>IO::Uncompress::Gunzip</code> to uncompress all the gzip data streams, include the <code>MultiStream</code> option, as shown below</p>

<pre><code class="plaintext">$ perl -MIO::Uncompress::Gunzip=:all -e &#39;gunzip &quot;x.gz&quot; =&gt; \*STDOUT, MultiStream =&gt; 1&#39;
abc
def</code></pre>

<h2 id="Reading-bgzip-files-with-IO::Uncompress::Gunzip"><a class="permalink" href="./IO::Compress::FAQ.html#Reading-bgzip-files-with-IO::Uncompress::Gunzip">#</a><a id="Reading"></a>Reading bgzip files with IO::Uncompress::Gunzip</h2>

<p>A <code>bgzip</code> file consists of a series of valid gzip-compliant data streams concatenated together. To read a file created by <code>bgzip</code> with <code>IO::Uncompress::Gunzip</code> use the <code>MultiStream</code> option as shown in the previous section.</p>

<p>See the section titled &quot;The BGZF compression format&quot; in <a href="http://samtools.github.io/hts-specs/SAMv1.pdf">http://samtools.github.io/hts-specs/SAMv1.pdf</a> for a definition of <code>bgzip</code>.</p>

<h1 id="ZLIB"><a class="permalink" href="./IO::Compress::FAQ.html#ZLIB">#</a>ZLIB</h1>

<h2 id="Zlib-Resources"><a class="permalink" href="./IO::Compress::FAQ.html#Zlib-Resources">#</a><a id="Zlib"></a>Zlib Resources</h2>

<p>The primary site for the <i>zlib</i> compression library is <a href="http://www.zlib.org">http://www.zlib.org</a>.</p>

<h1 id="Bzip2"><a class="permalink" href="./IO::Compress::FAQ.html#Bzip2">#</a>Bzip2</h1>

<h2 id="Bzip2-Resources"><a class="permalink" href="./IO::Compress::FAQ.html#Bzip2-Resources">#</a><a id="Bzip21"></a>Bzip2 Resources</h2>

<p>The primary site for bzip2 is <a href="http://www.bzip.org">http://www.bzip.org</a>.</p>

<h2 id="Dealing-with-Concatenated-bzip2-files"><a class="permalink" href="./IO::Compress::FAQ.html#Dealing-with-Concatenated-bzip2-files">#</a><a id="Dealing1"></a>Dealing with Concatenated bzip2 files</h2>

<p>If the bunzip2 program encounters a file containing multiple bzip2 files concatenated together it will automatically uncompress them all. The example below illustrates this behaviour</p>

<pre><code class="plaintext">$ echo abc | bzip2 -c &gt;x.bz2
$ echo def | bzip2 -c &gt;&gt;x.bz2
$ bunzip2 -c x.bz2
abc
def</code></pre>

<p>By default <code>IO::Uncompress::Bunzip2</code> will <i>not</i> behave like the bunzip2 program. It will only uncompress the first bunzip2 data stream in the file, as shown below</p>

<pre><code class="plaintext">$ perl -MIO::Uncompress::Bunzip2=:all -e &#39;bunzip2 &quot;x.bz2&quot; =&gt; \*STDOUT&#39;
abc</code></pre>

<p>To force <code>IO::Uncompress::Bunzip2</code> to uncompress all the bzip2 data streams, include the <code>MultiStream</code> option, as shown below</p>

<pre><code class="plaintext">$ perl -MIO::Uncompress::Bunzip2=:all -e &#39;bunzip2 &quot;x.bz2&quot; =&gt; \*STDOUT, MultiStream =&gt; 1&#39;
abc
def</code></pre>

<h2 id="Interoperating-with-Pbzip2"><a class="permalink" href="./IO::Compress::FAQ.html#Interoperating-with-Pbzip2">#</a><a id="Interoperating"></a>Interoperating with Pbzip2</h2>

<p>Pbzip2 (<a href="http://compression.ca/pbzip2/">http://compression.ca/pbzip2/</a>) is a parallel implementation of bzip2. The output from pbzip2 consists of a series of concatenated bzip2 data streams.</p>

<p>By default <code>IO::Uncompress::Bzip2</code> will only uncompress the first bzip2 data stream in a pbzip2 file. To uncompress the complete pbzip2 file you must include the <code>MultiStream</code> option, like this.</p>

<pre><code>bunzip2 $input =&gt; \$output, MultiStream =&gt; 1
    or die &quot;bunzip2 failed: $Bunzip2Error\n&quot;;</code></pre>

<h1 id="HTTP-&amp;-NETWORK"><a class="permalink" href="./IO::Compress::FAQ.html#HTTP-&amp;-NETWORK">#</a><a id="HTTP"></a><a id="HTTP-NETWORK"></a>HTTP &amp; NETWORK</h1>

<h2 id="Apache::GZip-Revisited"><a class="permalink" href="./IO::Compress::FAQ.html#Apache::GZip-Revisited">#</a><a id="Apache"></a>Apache::GZip Revisited</h2>

<p>Below is a mod_perl Apache compression module, called <code>Apache::GZip</code>, taken from <a href="http://perl.apache.org/docs/tutorials/tips/mod_perl_tricks/mod_perl_tricks.html#On_the_Fly_Compression">http://perl.apache.org/docs/tutorials/tips/mod_perl_tricks/mod_perl_tricks.html#On_the_Fly_Compression</a></p>

<pre><code>package Apache::GZip;
#File: Apache::GZip.pm

use strict vars;
use Apache::Constants &#39;:common&#39;;
use Compress::Zlib;
use IO::File;
use constant GZIP_MAGIC =&gt; 0x1f8b;
use constant OS_MAGIC =&gt; 0x03;

sub handler {
    my $r = shift;
    my ($fh,$gz);
    my $file = $r-&gt;filename;
    return DECLINED unless $fh=IO::File-&gt;new($file);
    $r-&gt;header_out(&#39;Content-Encoding&#39;=&gt;&#39;gzip&#39;);
    $r-&gt;send_http_header;
    return OK if $r-&gt;header_only;

    tie *STDOUT,&#39;Apache::GZip&#39;,$r;
    print($_) while &lt;$fh&gt;;
    untie *STDOUT;
    return OK;
}

sub TIEHANDLE {
    my($class,$r) = @_;
    # initialize a deflation stream
    my $d = deflateInit(-WindowBits=&gt;-MAX_WBITS()) || return undef;

    # gzip header -- don&#39;t ask how I found out
    $r-&gt;print(pack(&quot;nccVcc&quot;,GZIP_MAGIC,Z_DEFLATED,0,time(),0,OS_MAGIC));

    return bless { r   =&gt; $r,
                   crc =&gt;  crc32(undef),
                   d   =&gt; $d,
                   l   =&gt;  0
                 },$class;
}

sub PRINT {
    my $self = shift;
    foreach (@_) {
      # deflate the data
      my $data = $self-&gt;{d}-&gt;deflate($_);
      $self-&gt;{r}-&gt;print($data);
      # keep track of its length and crc
      $self-&gt;{l} += length($_);
      $self-&gt;{crc} = crc32($_,$self-&gt;{crc});
    }
}

sub DESTROY {
   my $self = shift;

   # flush the output buffers
   my $data = $self-&gt;{d}-&gt;flush;
   $self-&gt;{r}-&gt;print($data);

   # print the CRC and the total length (uncompressed)
   $self-&gt;{r}-&gt;print(pack(&quot;LL&quot;,@{$self}{qw/crc l/}));
}

1;</code></pre>

<p>Here&#39;s the Apache configuration entry you&#39;ll need to make use of it. Once set it will result in everything in the /compressed directory will be compressed automagically.</p>

<pre><code class="plaintext">&lt;Location /compressed&gt;
   SetHandler  perl-script
   PerlHandler Apache::GZip
&lt;/Location&gt;</code></pre>

<p>Although at first sight there seems to be quite a lot going on in <code>Apache::GZip</code>, you could sum up what the code was doing as follows -- read the contents of the file in <code>$r-&gt;filename</code>, compress it and write the compressed data to standard output. That&#39;s all.</p>

<p>This code has to jump through a few hoops to achieve this because</p>

<ol>

<li><p>The gzip support in <code>Compress::Zlib</code> version 1.x can only work with a real filesystem filehandle. The filehandles used by Apache modules are not associated with the filesystem.</p>

</li>
<li><p>That means all the gzip support has to be done by hand - in this case by creating a tied filehandle to deal with creating the gzip header and trailer.</p>

</li>
</ol>

<p><code>IO::Compress::Gzip</code> doesn&#39;t have that filehandle limitation (this was one of the reasons for writing it in the first place). So if <code>IO::Compress::Gzip</code> is used instead of <code>Compress::Zlib</code> the whole tied filehandle code can be removed. Here is the rewritten code.</p>

<pre><code>package Apache::GZip;

use strict vars;
use Apache::Constants &#39;:common&#39;;
use IO::Compress::Gzip;
use IO::File;

sub handler {
    my $r = shift;
    my ($fh,$gz);
    my $file = $r-&gt;filename;
    return DECLINED unless $fh=IO::File-&gt;new($file);
    $r-&gt;header_out(&#39;Content-Encoding&#39;=&gt;&#39;gzip&#39;);
    $r-&gt;send_http_header;
    return OK if $r-&gt;header_only;

    my $gz = IO::Compress::Gzip-&gt;new( &#39;-&#39;, Minimal =&gt; 1 )
        or return DECLINED ;

    print $gz $_ while &lt;$fh&gt;;

    return OK;
}</code></pre>

<p>or even more succinctly, like this, using a one-shot gzip</p>

<pre><code>package Apache::GZip;

use strict vars;
use Apache::Constants &#39;:common&#39;;
use IO::Compress::Gzip qw(gzip);

sub handler {
    my $r = shift;
    $r-&gt;header_out(&#39;Content-Encoding&#39;=&gt;&#39;gzip&#39;);
    $r-&gt;send_http_header;
    return OK if $r-&gt;header_only;

    gzip $r-&gt;filename =&gt; &#39;-&#39;, Minimal =&gt; 1
      or return DECLINED ;

    return OK;
}

1;</code></pre>

<p>The use of one-shot <code>gzip</code> above just reads from <code>$r-&gt;filename</code> and writes the compressed data to standard output.</p>

<p>Note the use of the <code>Minimal</code> option in the code above. When using gzip for Content-Encoding you should <i>always</i> use this option. In the example above it will prevent the filename being included in the gzip header and make the size of the gzip data stream a slight bit smaller.</p>

<h2 id="Compressed-files-and-Net::FTP"><a class="permalink" href="./IO::Compress::FAQ.html#Compressed-files-and-Net::FTP">#</a><a id="Compressed"></a>Compressed files and Net::FTP</h2>

<p>The <code>Net::FTP</code> module provides two low-level methods called <code>stor</code> and <code>retr</code> that both return filehandles. These filehandles can used with the <code>IO::Compress/Uncompress</code> modules to compress or uncompress files read from or written to an FTP Server on the fly, without having to create a temporary file.</p>

<p>Firstly, here is code that uses <code>retr</code> to uncompressed a file as it is read from the FTP Server.</p>

<pre><code>use Net::FTP;
use IO::Uncompress::Gunzip qw(:all);

my $ftp = Net::FTP-&gt;new( ... )

my $retr_fh = $ftp-&gt;retr($compressed_filename);
gunzip $retr_fh =&gt; $outFilename, AutoClose =&gt; 1
    or die &quot;Cannot uncompress &#39;$compressed_file&#39;: $GunzipError\n&quot;;</code></pre>

<p>and this to compress a file as it is written to the FTP Server</p>

<pre><code>use Net::FTP;
use IO::Compress::Gzip qw(:all);

my $stor_fh = $ftp-&gt;stor($filename);
gzip &quot;filename&quot; =&gt; $stor_fh, AutoClose =&gt; 1
    or die &quot;Cannot compress &#39;$filename&#39;: $GzipError\n&quot;;</code></pre>

<h1 id="MISC"><a class="permalink" href="./IO::Compress::FAQ.html#MISC">#</a>MISC</h1>

<h2 id="Using-InputLength-to-uncompress-data-embedded-in-a-larger-file/buffer."><a class="permalink" href="./IO::Compress::FAQ.html#Using-InputLength-to-uncompress-data-embedded-in-a-larger-file/buffer.">#</a><a id="Using"></a><a id="Using-InputLength-to-uncompress-data-embedded-in-a-larger-file-buffer"></a>Using <code>InputLength</code> to uncompress data embedded in a larger file/buffer.</h2>

<p>A fairly common use-case is where compressed data is embedded in a larger file/buffer and you want to read both.</p>

<p>As an example consider the structure of a zip file. This is a well-defined file format that mixes both compressed and uncompressed sections of data in a single file.</p>

<p>For the purposes of this discussion you can think of a zip file as sequence of compressed data streams, each of which is prefixed by an uncompressed local header. The local header contains information about the compressed data stream, including the name of the compressed file and, in particular, the length of the compressed data stream.</p>

<p>To illustrate how to use <code>InputLength</code> here is a script that walks a zip file and prints out how many lines are in each compressed file (if you intend write code to walking through a zip file for real see <a href="./IO::Uncompress::Unzip.html#Walking-through-a-zip-file">&quot;Walking through a zip file&quot; in IO::Uncompress::Unzip</a> ). Also, although this example uses the zlib-based compression, the technique can be used by the other <code>IO::Uncompress::*</code> modules.</p>

<pre><code>use strict;
use warnings;

use IO::File;
use IO::Uncompress::RawInflate qw(:all);

use constant ZIP_LOCAL_HDR_SIG  =&gt; 0x04034b50;
use constant ZIP_LOCAL_HDR_LENGTH =&gt; 30;

my $file = $ARGV[0] ;

my $fh = IO::File-&gt;new( &quot;&lt;$file&quot; )
            or die &quot;Cannot open &#39;$file&#39;: $!\n&quot;;

while (1)
{
    my $sig;
    my $buffer;

    my $x ;
    ($x = $fh-&gt;read($buffer, ZIP_LOCAL_HDR_LENGTH)) == ZIP_LOCAL_HDR_LENGTH
        or die &quot;Truncated file: $!\n&quot;;

    my $signature = unpack (&quot;V&quot;, substr($buffer, 0, 4));

    last unless $signature == ZIP_LOCAL_HDR_SIG;

    # Read Local Header
    my $gpFlag             = unpack (&quot;v&quot;, substr($buffer, 6, 2));
    my $compressedMethod   = unpack (&quot;v&quot;, substr($buffer, 8, 2));
    my $compressedLength   = unpack (&quot;V&quot;, substr($buffer, 18, 4));
    my $uncompressedLength = unpack (&quot;V&quot;, substr($buffer, 22, 4));
    my $filename_length    = unpack (&quot;v&quot;, substr($buffer, 26, 2));
    my $extra_length       = unpack (&quot;v&quot;, substr($buffer, 28, 2));

    my $filename ;
    $fh-&gt;read($filename, $filename_length) == $filename_length
        or die &quot;Truncated file\n&quot;;

    $fh-&gt;read($buffer, $extra_length) == $extra_length
        or die &quot;Truncated file\n&quot;;

    if ($compressedMethod != 8 &amp;&amp; $compressedMethod != 0)
    {
        warn &quot;Skipping file &#39;$filename&#39; - not deflated $compressedMethod\n&quot;;
        $fh-&gt;read($buffer, $compressedLength) == $compressedLength
            or die &quot;Truncated file\n&quot;;
        next;
    }

    if ($compressedMethod == 0 &amp;&amp; $gpFlag &amp; 8 == 8)
    {
        die &quot;Streamed Stored not supported for &#39;$filename&#39;\n&quot;;
    }

    next if $compressedLength == 0;

    # Done reading the Local Header

    my $inf = IO::Uncompress::RawInflate-&gt;new( $fh,
                        Transparent =&gt; 1,
                        InputLength =&gt; $compressedLength )
      or die &quot;Cannot uncompress $file [$filename]: $RawInflateError\n&quot;  ;

    my $line_count = 0;

    while (&lt;$inf&gt;)
    {
        ++ $line_count;
    }

    print &quot;$filename: $line_count\n&quot;;
}</code></pre>

<p>The majority of the code above is concerned with reading the zip local header data. The code that I want to focus on is at the bottom.</p>

<pre><code>while (1) {

    # read local zip header data
    # get $filename
    # get $compressedLength

    my $inf = IO::Uncompress::RawInflate-&gt;new( $fh,
                        Transparent =&gt; 1,
                        InputLength =&gt; $compressedLength )
      or die &quot;Cannot uncompress $file [$filename]: $RawInflateError\n&quot;  ;

    my $line_count = 0;

    while (&lt;$inf&gt;)
    {
        ++ $line_count;
    }

    print &quot;$filename: $line_count\n&quot;;
}</code></pre>

<p>The call to <code>IO::Uncompress::RawInflate</code> creates a new filehandle <code>$inf</code> that can be used to read from the parent filehandle <code>$fh</code>, uncompressing it as it goes. The use of the <code>InputLength</code> option will guarantee that <i>at most</i> <code>$compressedLength</code> bytes of compressed data will be read from the <code>$fh</code> filehandle (The only exception is for an error case like a truncated file or a corrupt data stream).</p>

<p>This means that once RawInflate is finished <code>$fh</code> will be left at the byte directly after the compressed data stream.</p>

<p>Now consider what the code looks like without <code>InputLength</code></p>

<pre><code>while (1) {

    # read local zip header data
    # get $filename
    # get $compressedLength

    # read all the compressed data into $data
    read($fh, $data, $compressedLength);

    my $inf = IO::Uncompress::RawInflate-&gt;new( \$data,
                        Transparent =&gt; 1 )
      or die &quot;Cannot uncompress $file [$filename]: $RawInflateError\n&quot;  ;

    my $line_count = 0;

    while (&lt;$inf&gt;)
    {
        ++ $line_count;
    }

    print &quot;$filename: $line_count\n&quot;;
}</code></pre>

<p>The difference here is the addition of the temporary variable <code>$data</code>. This is used to store a copy of the compressed data while it is being uncompressed.</p>

<p>If you know that <code>$compressedLength</code> isn&#39;t that big then using temporary storage won&#39;t be a problem. But if <code>$compressedLength</code> is very large or you are writing an application that other people will use, and so have no idea how big <code>$compressedLength</code> will be, it could be an issue.</p>

<p>Using <code>InputLength</code> avoids the use of temporary storage and means the application can cope with large compressed data streams.</p>

<p>One final point -- obviously <code>InputLength</code> can only be used whenever you know the length of the compressed data beforehand, like here with a zip file.</p>

<h1 id="SUPPORT"><a class="permalink" href="./IO::Compress::FAQ.html#SUPPORT">#</a>SUPPORT</h1>

<p>General feedback/questions/bug reports should be sent to <a href="https://github.com/pmqs//issues">https://github.com/pmqs//issues</a> (preferred) or <a href="https://rt.cpan.org/Public/Dist/Display.html?Name=">https://rt.cpan.org/Public/Dist/Display.html?Name=</a>.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="./IO::Compress::FAQ.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="./Compress::Zlib.html">Compress::Zlib</a>, <a href="./IO::Compress::Gzip.html">IO::Compress::Gzip</a>, <a href="./IO::Uncompress::Gunzip.html">IO::Uncompress::Gunzip</a>, <a href="./IO::Compress::Deflate.html">IO::Compress::Deflate</a>, <a href="./IO::Uncompress::Inflate.html">IO::Uncompress::Inflate</a>, <a href="./IO::Compress::RawDeflate.html">IO::Compress::RawDeflate</a>, <a href="./IO::Uncompress::RawInflate.html">IO::Uncompress::RawInflate</a>, <a href="./IO::Compress::Bzip2.html">IO::Compress::Bzip2</a>, <a href="./IO::Uncompress::Bunzip2.html">IO::Uncompress::Bunzip2</a>, <a href="./IO::Compress::Lzma.html">IO::Compress::Lzma</a>, <a href="./IO::Uncompress::UnLzma.html">IO::Uncompress::UnLzma</a>, <a href="./IO::Compress::Xz.html">IO::Compress::Xz</a>, <a href="./IO::Uncompress::UnXz.html">IO::Uncompress::UnXz</a>, <a href="./IO::Compress::Lzip.html">IO::Compress::Lzip</a>, <a href="./IO::Uncompress::UnLzip.html">IO::Uncompress::UnLzip</a>, <a href="./IO::Compress::Lzop.html">IO::Compress::Lzop</a>, <a href="./IO::Uncompress::UnLzop.html">IO::Uncompress::UnLzop</a>, <a href="./IO::Compress::Lzf.html">IO::Compress::Lzf</a>, <a href="./IO::Uncompress::UnLzf.html">IO::Uncompress::UnLzf</a>, <a href="./IO::Compress::Zstd.html">IO::Compress::Zstd</a>, <a href="./IO::Uncompress::UnZstd.html">IO::Uncompress::UnZstd</a>, <a href="./IO::Uncompress::AnyInflate.html">IO::Uncompress::AnyInflate</a>, <a href="./IO::Uncompress::AnyUncompress.html">IO::Uncompress::AnyUncompress</a></p>

<p><a href="./IO::Compress::FAQ.html">IO::Compress::FAQ</a></p>

<p><a href="./File::GlobMapper.html">File::GlobMapper</a>, <a href="./Archive::Zip.html">Archive::Zip</a>, <a href="./Archive::Tar.html">Archive::Tar</a>, <a href="./IO::Zlib.html">IO::Zlib</a></p>

<h1 id="AUTHOR"><a class="permalink" href="./IO::Compress::FAQ.html#AUTHOR">#</a>AUTHOR</h1>

<p>This module was written by Paul Marquess, <code>pmqs@cpan.org</code>.</p>

<h1 id="MODIFICATION-HISTORY"><a class="permalink" href="./IO::Compress::FAQ.html#MODIFICATION-HISTORY">#</a><a id="MODIFICATION"></a>MODIFICATION HISTORY</h1>

<p>See the Changes file.</p>

<h1 id="COPYRIGHT-AND-LICENSE"><a class="permalink" href="./IO::Compress::FAQ.html#COPYRIGHT-AND-LICENSE">#</a><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<p>Copyright (c) 2005-2021 Paul Marquess. All rights reserved.</p>

<p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
